import {
  LOGIN,
  NOLOGIN,
  GET_USERS,
  DEL_USERS,
  DEL_TOKEN,
  REGISTER_USER,
  GET_IDENTITY,
  ADD_IDENTITY,
} from "../../actionType";
import sess from "../../../utils/sess";
// LOGIN === loginFn

export default {
  // lgoinFn()
  [LOGIN](state, payload) {
    // 写入token到sessionStorage中
    console.log(payload);
    sess.set("token", payload.token);

    state.token = payload;
    // delete payload.token
    state.islogin = true;
    state.userinfo = payload;
  },
  // [NOLOGIN](state) {
  //   sess.set("token", "");

  //   state.token = "";
  //   state.islogin = false;
  //   state.userinfo = {};
  // },
  [GET_USERS](state, data) {
    state.userinfo = data;
  },
  [DEL_USERS](state, data) {
    state.users = state.users.filter((item) => item.date != data.date);
  },
  [DEL_TOKEN](state, data) {
    sess.del("token");
    state.token = "";
  },
  [REGISTER_USER](state, data) {
    // state.token = data;
  },
  [GET_IDENTITY](state, data) {
    state.identity = data;
  },
  [ADD_IDENTITY](state, data) {
    state.identity = [...state.identity, data];
  },
};
